<template>
  <div>
    <section class="jumbotron">
      <h3 class="jumbotron-heading">Search Github Users</h3>
      <div>
        <input
          type="text"
          placeholder="请输入搜索内容"
          v-model="keyword"
          @keyup.enter="getUser"
        />&nbsp;<button @click="getUser">搜索</button>
      </div>
    </section>
  </div>
</template>

<script>
// import axios from "axios";
export default {
  name: "Search",
  data() {
    return {
      keyword: "",
    };
  },
  components: {},
  mounted() {},
  methods: {
    getUser() {
      // 请求前更新list数据
      this.$bus.$emit("updataList", {
        isLoading: true,
        errMsg: "",
        users: [],
        isFirst: false,
      });
      this.$http.get(`https://api.github.com/search/users?q=${this.keyWord}`).then(
        (resopnse) => {
          console.log("成功获取");
          // 请求成功后更新list数据
          this.$bus.$emit("updataList", {
            isLoading: false,
            errMsg: "",
            users: resopnse.data.items,
          })
        },
        (error) => {
          console.log("获取失败", {
            isLoading: false,
            errMsg: error.message,
            users: [],
          })
        }
      )
      // axios.get(`https://api.github.com/search/users?q=${this.keyWord}`).then(
      //   (resopnse) => {
      //     console.log("成功获取");
      //     // 请求成功后更新list数据
      //     this.$bus.$emit("updataList", {
      //       isLoading: false,
      //       errMsg: "",
      //       users: resopnse.data.items,
      //     });
      //   },
      //   (error) => {
      //     console.log("获取失败", {
      //       isLoading: false,
      //       errMsg: error.message,
      //       users: [],
      //     });
      //   }
      // );
    },
  },
};
</script>

<style scoped>
</style>
